package com.ld.security.server.admin.modules.gl.service.impl;

import com.ld.security.common.mybatis.util.JdbcUtil;
import com.ld.security.server.admin.modules.gl.entity.GlConfigEntity;
import com.ld.security.server.admin.modules.gl.mapping.GlConfigMapping;
import com.ld.security.server.admin.modules.gl.service.IGlConfigService;
import com.ld.security.common.mybatis.base.po.IdPo;
import com.ld.security.common.mybatis.base.service.ISuperServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class GlConfigServiceImpl  extends ISuperServiceImpl<GlConfigEntity>
implements
        IGlConfigService {

        @Autowired
        GlConfigMapping glConfigMapping;



        @Override
        public int useConfig(IdPo po) {
                GlConfigEntity e = this.getById(po.getId());

                GlConfigEntity config =   this.newInstance();
                config.setId(po.getId());
                config.setSwitchCode(e.getSwitchCode());
                config.setSwitchValue(true);
                JdbcUtil.proxyOpenSwitch(config);
                return glConfigMapping.updateById(config);
        }


        @Override
        public GlConfigEntity getDefultConfig(String code) {
                GlConfigEntity config =   this.newInstance();
                config.setSwitchCode(code);
                config.setSwitchValue(true);

                return this.findOne(config);
        }
}
